package com.tourscool.springboot.starter.utils;

import org.slf4j.MDC;

import java.util.UUID;

/**
 * @author Cedric
 * @date 2022/07/06 17:24
 * @description TraceId工具类
 */
public class TraceIdUtil {
    private static final String TRACE_ID = "traceId";

    public static void set() {
        MDC.put(TRACE_ID, generate());
    }

    public static String get() {
        return MDC.get(TRACE_ID);
    }

    public static void remove() {
        MDC.remove(TRACE_ID);
    }

    public static String generate() {
        return UUID.randomUUID().toString().replace("-", "").substring(0, 16);
    }
}